package com.hengpeng.itfin.persist.impl;

import java.util.List;

import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Repository;

import com.hengpeng.common.persist.AbstractDao;
import com.hengpeng.common.persist.entity.AbstractEntity;
import com.hengpeng.common.persist.query.DynamicQuery;
import com.hengpeng.itfin.persist.CommonJdbcdao;

@Repository
@Lazy
public class CommonJdbcdaoImpl extends AbstractDao<AbstractEntity> implements CommonJdbcdao
{
	public CommonJdbcdaoImpl()
	{
		super.setProviderType(0);
	}

	@Override
	public <T extends AbstractEntity> List<T> findEntityByDynamicQuery(DynamicQuery dynamicQuery, Class<T> type)
	{
		super.setExactType(type);
		return super.findAllByDynamicQuery(dynamicQuery, type);
	}

	public <T extends AbstractEntity> T getByDynamicQuery(DynamicQuery dynamicQuery, Class<T> type)
	{
		List<T> list = super.findAllByDynamicQuery(dynamicQuery, type);
		if (list != null && list.size() > 0)
		{
			return list.get(0);
		}
		return null;
	}
}
